package IO;
/*
try块中某句代码如果出现了异常，那么try块中这句代码以下的代码都不执行了
try语句中如果不出现异常，catch块不执行
 */

public class TryCatchDemo {
    public static void main(String[] args) {
        System.out.println("start");
        try{
            String line= null;
            System.out.println(line.length());

            String line2=" ";
            System.out.println(line2.charAt(0));

        }catch (NullPointerException e){
            System.out.println("出现了空指针异常");
        }catch(StringIndexOutOfBoundsException e){
            System.out.println("出现了下标越界异常");
        }catch (Exception e){
            System.out.println("出现异常了");
        }

        System.out.println("ending");
    }

}
